java.lang.Object
edu.claflin.finder.algo.clustering.struct.fast_greedy_struct.SparseMatrix

public class SparseMatrix extends Object
SparseMatrix is a sparse matrix with row format.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private int
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SparseMatrix(int rows)
    empty sparse matrix with allocated number of rows
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int i, int j, double q)
    Add the given j index, q value pair to the ith tree and heap
    void
    addHeap(int i, int j, double q)
    Add the given j index, q value pair to the ith heap.
    void
    addTree(int i, int j, double q)
    Add the given j index, q value pair to the ith tree.
    void
    clearRow(int i)
    Clear the ith tree and heap
    get(int i, int j)
    get number at index or null if not set.
    getMax(int i)
    Get the maximum q value at row i
    void
    mergeTrees(int j, int i)
    Merge Trees j and i into j, summing values if the same column occurs.
    void
    rebuildHeap(int j)
    Rebuild heap j with the tree j
    private void
    removeFromTree(int i, int j)
     
    int
    get the rows of the matrix
    void
    set(int i, int j, double q)
    Set the q value at the ith tree and heap's j column.
    void
    setHeap(int i, int j, double q)
    Set the value q and the ith heap's j column.
    void
    setTree(int i, int j, double q)
    Set value q and the ith tree's j column.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • SparseMatrix

      public SparseMatrix(int rows)
      empty sparse matrix with allocated number of rows
      Parameters:
      rows - the number of rows
  • Method Details

    • rows

      public int rows()
      get the rows of the matrix
      Returns:
      the number of rows in the matrix
    • add

      public void add(int i, int j, double q)
      Add the given j index, q value pair to the ith tree and heap
      Parameters:
      i - the row to add
      j - the j index
      q - the q value
    • addTree

      public void addTree(int i, int j, double q)
      Add the given j index, q value pair to the ith tree.
      Parameters:
      i - the row to add
      j - the j index
      q - the q value
    • addHeap

      public void addHeap(int i, int j, double q)
      Add the given j index, q value pair to the ith heap.
      Parameters:
      i - the row to add
      j - the j index
      q - the q value
    • get

      public Double get(int i, int j)
      get number at index or null if not set.
      Parameters:
      i - the row to search
      j - the colum to search
      Returns:
      the q value if it exists or null
    • setTree

      public void setTree(int i, int j, double q)
      Set value q and the ith tree's j column. add it if it's not there.
      Parameters:
      i - the row to set in
      j - the column to set in
      q - the new q value
    • setHeap

      public void setHeap(int i, int j, double q)
      Set the value q and the ith heap's j column. add it if it's not there.
      Parameters:
      i - the row to set in
      j - the column to set in
      q - the new q value
    • set

      public void set(int i, int j, double q)
      Set the q value at the ith tree and heap's j column.
      Parameters:
      i - the row to set in
      j - the column to set in
      q - the new q value
    • removeFromTree

      private void removeFromTree(int i, int j)
    • getMax

      public HeapNodeFG getMax(int i)
      Get the maximum q value at row i
      Parameters:
      i - the row to search in
      Returns:
      the maximum q value
    • clearRow

      public void clearRow(int i)
      Clear the ith tree and heap
      Parameters:
      i - the row to clear in
    • mergeTrees

      public void mergeTrees(int j, int i)
      Merge Trees j and i into j, summing values if the same column occurs.
      Parameters:
      j - the tree to expand
      i - the tree that offers its Nodes
    • rebuildHeap

      public void rebuildHeap(int j)
      Rebuild heap j with the tree j
      Parameters:
      j - the heap to rebuild
    • toString

      public String toString()
      Overrides:
      toString in class Object